﻿Imports System.Data.SqlClient

Public Class clsParametrosGeneralesEvaluacion
    Private mintID As Integer
    Private mstrNombre As String
    Private mdblPorcentaje As Double
    Public Property ID() As Integer
        Get
            Return mintID
        End Get
        Set(ByVal value As Integer)
            mintID = value
        End Set
    End Property
    Public Property Nombre() As String
        Get
            Return mstrNombre
        End Get
        Set(ByVal value As String)
            mstrNombre = value
        End Set
    End Property
    Public Property Porcentaje() As Double
        Get
            Return mdblPorcentaje
        End Get
        Set(ByVal value As Double)
            mdblPorcentaje = value
        End Set
    End Property

    Public Sub New()
        mintID = 0
        mstrNombre = ""
        mdblPorcentaje = 0
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into ParametrosGeneralesEvaluacion (" & _
                            "Nombre," & _
                            "Porcentaje) " & _
                            "VALUES (" & _
                            "substring(@Nombre,1,100)," & _
                            "@Porcentaje)"
                         


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("Nombre", mstrNombre)
        Command.Parameters.AddWithValue("Porcentaje", mdblPorcentaje)

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar porcentaje ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Public Sub Actualizar()

        Dim strSqlQry As String
        Dim cnConn As New SqlConnection

        cnConn.ConnectionString = CitraConnection
        strSqlQry = "Update ParametrosGeneralesEvaluacion Set " & _
                    "Porcentaje=@Porcentaje " & _
                    "Where ID=@ID"

        Dim Command As New SqlCommand(strSqlQry, cnConn)

        Command.Parameters.AddWithValue("id", mintID)
        Command.Parameters.AddWithValue("Porcentaje", mdblPorcentaje)
        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el porcentaje ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If



    End Sub
End Class
